package cn.scw.project.goods.controller;

import cn.scw.common.constant.SysConsts;
import cn.scw.framework.aspectj.lang.annotation.Log;
import cn.scw.framework.aspectj.lang.enums.BusinessType;
import cn.scw.framework.web.controller.BaseController;
import cn.scw.framework.web.domain.AjaxResult;
import cn.scw.framework.web.page.TableDataInfo;
import cn.scw.project.goods.domain.netework.bean.GCommodityTypeAddReq;
import cn.scw.project.goods.domain.netework.bean.GCommodityTypeListReq;
import cn.scw.project.goods.domain.vo.GCommodityTypeVo;
import cn.scw.project.goods.service.IGCommodityTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品详细分类Controller
 *
 * @author api
 * @date 2020-05-25
 */
@Api(tags = "商品详细分类")
@RestController
@RequestMapping(SysConsts.CONTEXT_PATH+"/goods/commodity/type")
public class GCommodityTypeController extends BaseController {
    @Autowired
    private IGCommodityTypeService gCommodityTypeService;

    @ApiOperation("查询商品详细分类列表")
    @GetMapping("/list")
    public TableDataInfo list(GCommodityTypeListReq req) {
        startPage();
        List<GCommodityTypeVo> list = gCommodityTypeService.selectGCommodityTypeList(req);
        return getDataTable(list);
    }

    @ApiOperation("获取商品详细分类详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(gCommodityTypeService.selectGCommodityTypeById(id));
    }

    @ApiOperation("新增商品详细分类")
    @Log(title = "商品详细分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(GCommodityTypeAddReq req) {
        return toAjax(gCommodityTypeService.insertGCommodityType(req));
    }

    @ApiOperation("修改商品详细分类")
    @Log(title = "商品详细分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(GCommodityTypeAddReq req) {
        return toAjax(gCommodityTypeService.updateGCommodityType(req));
    }

    @ApiOperation("删除商品详细分类")
    @Log(title = "商品详细分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(gCommodityTypeService.deleteGCommodityTypeByIds(ids));
    }
}
